#include "Tester.hpp"
#include "TimeLine.hpp"
#include <QxtLogger>
#include "Actor3DEvent.hpp"
Tester::Tester()
{
    qxtLog->info("created a Test Actor");
    tl.start();
    //tl.insert(new Actor3DEvent(this,"x-position-static",10.0f,1.0f));
    //tl.insert(new Actor3DEvent(this,"y-position-static",10.0f,2.0f));
    //tl.insert(new Actor3DEvent(this,"y-position-static",-10.0f,3.0f));
    //tl.insert(new Actor3DEvent(this,"x-position-velocity",10.0f,4.0f));

    getF("x-rotation-static") = 25.0f;
    getF("y-rotation-velocity") = 15.0f;
}

void Tester::update(float f) {
    tl.update(f);
    Actor3D::update(f);
    c.setRgbF(1.0,1.0,1.0,1.0);
}

void Tester::action() {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(getF("x-position-static"),getF("y-position-static"),getF("y-position-static"));
    glRotatef(getF("x-rotation-static"),1.0f,0.0f,0.0f);
    glRotatef(getF("y-rotation-static"),0.0f,1.0f,0.0f);
    glRotatef(getF("z-rotation-static"),0.0f,0.0f,1.0f);

    // screw it, let's draw a cube!
    glBegin(GL_QUADS);
        glColor3f(c.redF(),c.greenF(),c.blueF());

        // side front
        glNormal3f(0.0f,0.0f,1.0f);
        glColor3f(1.0,1.0,1.0); glVertex3f(0.5,0.5,0.5); // p1
        glColor3f(1.0,0.0,1.0); glVertex3f(0.5,-0.5,0.5); // p2
        glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,0.5); // p3
        glColor3f(1.0,1.0,0.0); glVertex3f(-0.5,0.5,0.5);// p4

        //side left
        glNormal3f(-1.0f,0.0f,0.0f);
        glColor3f(1.0,1.0,0.0); glVertex3f(-0.5,0.5,0.5);// p4
        glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,0.5); // p3
        glColor3f(0.0,1.0,0.0); glVertex3f(-0.5,0.5,-0.5);// p8
        glColor3f(0.0,0.0,0.0); glVertex3f(-0.5,-0.5,-0.5);// p7

        // side 3 (back)
        glNormal3f(0.0f,0.0f,-1.0f);
        glColor3f(0.0,1.0,0.0); glVertex3f(-0.5,0.5,-0.5);// p8
        glColor3f(0.0,0.0,0.0); glVertex3f(-0.5,-0.5,-0.5);// p7
        glColor3f(0.0,0.0,1.0); glVertex3f(0.5,-0.5,-0.5);// p6
        glColor3f(0.0,1.0,1.0); glVertex3f(0.5,0.5,-0.5);// p5

        //side right
        glNormal3f(1.0f,0.0f,0.0f);
        glColor3f(0.0,1.0,1.0); glVertex3f(0.5,0.5,-0.5);// p5
        glColor3f(0.0,0.0,1.0); glVertex3f(0.5,-0.5,-0.5);// p6
        glColor3f(1.0,0.0,1.0); glVertex3f(0.5,-0.5,0.5); // p2
        glColor3f(1.0,1.0,1.0); glVertex3f(0.5,0.5,0.5); // p1

        //top
        glNormal3f(0.0f,1.0f,0.0f);
        glColor3f(0.0,1.0,1.0); glVertex3f(0.5,0.5,-0.5);// p5
        glColor3f(1.0,1.0,1.0); glVertex3f(0.5,0.5,0.5); // p1
        glColor3f(1.0,1.0,0.0); glVertex3f(-0.5,0.5,0.5);// p4
        glColor3f(0.0,1.0,0.0); glVertex3f(-0.5,0.5,-0.5);// p8


        //bottom
        glNormal3f(0.0f,-1.0f,0.0f);
        glColor3f(1.0,0.0,1.0); glVertex3f(0.5,-0.5,0.5); // p2
        glColor3f(0.0,0.0,1.0); glVertex3f(0.5,-0.5,-0.5);// p6
        glColor3f(0.0,0.0,0.0); glVertex3f(-0.5,-0.5,-0.5);// p7
        glColor3f(1.0,0.0,0.0); glVertex3f(-0.5,-0.5,0.5); // p3

    glEnd();

    glBegin(GL_LINES);
        glColor3f(1.0f,1.0f,1.0f);
        glVertex3f(0.51,0.51,0.51);glVertex3f(0.51,-0.51,0.51); //1-2
        glVertex3f(0.51,-0.51,0.51);glVertex3f(-0.51,-0.51,0.51); //2-3
        glVertex3f(-0.51,-0.51,0.51);glVertex3f(-0.51,0.51,0.51); //3-4
        glVertex3f(-0.51,0.51,0.51);glVertex3f(0.51,0.51,0.51); //4-1
        glVertex3f(-0.51,0.51,-0.51);glVertex3f(-0.51,-0.51,-0.51);//7-8
        glVertex3f(-0.51,-0.51,-0.51);glVertex3f(0.51,-0.51,-0.51);// 6-7
        glVertex3f(0.51,-0.51,-0.51);glVertex3f(0.51,0.51,-0.51);// p5-6
        glVertex3f(0.51,0.51,-0.51);glVertex3f(-0.51,0.51,-0.51);//8-5
        glVertex3f(0.51,0.51,0.51);glVertex3f(0.51,0.51,-0.51);//1-5
        glVertex3f(0.51,-0.51,0.51);glVertex3f(0.51,-0.51,-0.51);//2-6
        glVertex3f(-0.51,-0.51,0.51);glVertex3f(-0.51,-0.51,-0.51); // 3-7
        glVertex3f(-0.51,0.51,0.51); glVertex3f(-0.51,0.51,-0.51);//4-8

    glEnd();

}

void Tester::receiveEvent(const QByteArray &event) {
    if(event == "KEY_DOWN") {
        c.setRgbF( c.redF() - 0.2,c.greenF() - 0.2,c.blueF() - 0.2,1.0);
    }else if(event == "KEY_UP") {
        c.setRgbF( c.redF() + 0.2,c.greenF() + 0.2,c.blueF() + 0.2,1.0);
    }
}

void Tester::load() {
}
